import 'package:flutter/material.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:xinxuan/common/button_util.dart';
import 'package:xinxuan/common/network_image_util.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/controllers/seckill_controller/seckill_order_page_controller.dart';
import 'package:xinxuan/router/app_routers.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:xinxuan/utils/refresh_util.dart';
import 'package:xinxuan/vo/seckill_order_list_vo.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class SeckillOrderGoodArr extends StatefulWidget {

  final CommonPageController commonPageController = Get.find();

  final SeckillOrderListVo seckillOrderListVo;
  final SeckillOrderPageController seckillOrderPageController;

  SeckillOrderGoodArr({
    required this.seckillOrderListVo,
    required this.seckillOrderPageController
  });
  @override
  _SeckillOrderGoodArrState createState() => _SeckillOrderGoodArrState();
}

class _SeckillOrderGoodArrState extends State<SeckillOrderGoodArr> with AutomaticKeepAliveClientMixin {
  
  @override
  Widget build(BuildContext context) {
    super.build(context);
    if (widget.seckillOrderListVo.data!.length <= 0) {
      return Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Image.asset(
              'assets/icons/icon_order_list_def.png',
              width: 273.w,
              height: 146.h,
            ),
            SizedBox(height: 10.h),
            Text(
              '还没订单~去下一单！',
              style: TextStyle(
                color: textSubtitleColor,
                fontSize: 14.sp
              ),
            )
          ],
        ),
      );
    }
    return RefreshUtil.easyRefresh(
      onRefresh: () async {
        widget.seckillOrderPageController.getSeckillTabItemOrderList(widget.seckillOrderPageController.tabIndex.value);
      },
      onLoad: () async {
        widget.seckillOrderPageController.onloadSeckillOrderList();
      },
      // slivers: widget.seckillOrderListVo.data!.map((item) {
      //   return SliverToBoxAdapter(
      //     child: Container(
      //       padding: EdgeInsets.symmetric(horizontal: 16.w),
      //       margin: EdgeInsets.only(top: 6.h),
      //       child: InkWellUtil.shakeProofInkWell(Container(
      //         decoration: BoxDecoration(
      //           color: bgWhiteColor,
      //           borderRadius: BorderRadius.circular(5.w)
      //         ),
      //         child: Container(
      //           padding: EdgeInsets.symmetric(horizontal: 8.w),
      //           child: Column(
      //             crossAxisAlignment: CrossAxisAlignment.start,
      //             children: [
      //               Container(
      //                 padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 10.h),
      //                 decoration: BoxDecoration(
      //                   border: Border(
      //                     bottom: BorderSide(
      //                       width: .5,
      //                       color: lineColor
      //                     )
      //                   )
      //                 ),
      //                 child: Row(
      //                   children: [
      //                     Expanded(child: Text(
      //                       '订单号：${item.orderSn}',
      //                       overflow: TextOverflow.ellipsis,
      //                       maxLines: 1,
      //                       style: TextStyle(
      //                         color: textBlackColor,
      //                         fontWeight: FontWeight.bold,
      //                         fontSize: 12.sp
      //                       ),
      //                     )),
      //                     Text(
      //                       '${item.statusStr}',
      //                       style: TextStyle(
      //                         color: mainTextColor,
      //                         fontSize: 12.sp
      //                       ),
      //                     )
      //                   ],
      //                 ),
      //               ),
      //               Container(
      //                 padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 10.h),
      //                 decoration: BoxDecoration(
      //                   border: Border(
      //                     bottom: BorderSide(
      //                       width: .5,
      //                       color: lineColor
      //                     )
      //                   )
      //                 ),
      //                 child: Column(
      //                   children: [
      //                     Column(
      //                       children: item.products!.map((productItem) {
      //                         return Container(
      //                           // margin: EdgeInsets.only(bottom: 10.w),
      //                           child: Row(
      //                             children: [
      //                               NetworkImageUtil(
      //                                 url: productItem.image ?? '', 
      //                                 width: 64.w, 
      //                                 height: 64.w,
      //                                 borderRadius: 5.w,
      //                               ),
      //                               SizedBox(width: 11.w),
      //                               Expanded(child: Container(
      //                                 constraints: BoxConstraints(
      //                                   minHeight: 64.w
      //                                 ),
      //                                 child: Column(
      //                                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
      //                                   crossAxisAlignment: CrossAxisAlignment.start,
      //                                   children: [
      //                                     Text(
      //                                       '${productItem.title}',
      //                                       overflow: TextOverflow.ellipsis,
      //                                       maxLines: 2,
      //                                       style: TextStyle(
      //                                         fontSize: 14.sp,
      //                                         color: textBlackColor
      //                                       ),
      //                                     ),
      //                                     Row(
      //                                       mainAxisAlignment: MainAxisAlignment.spaceBetween,
      //                                       children: [
      //                                         Text(
      //                                           '${item.createdAt}',
      //                                           style: TextStyle(
      //                                             color: textSubtitleColor,
      //                                             fontSize: 12.sp
      //                                           ),
      //                                         ),
      //                                         Text.rich(
      //                                           TextSpan(
      //                                             text: '¥',
      //                                             style: TextStyle(
      //                                               color: mainTextColor,
      //                                               fontSize: 12.sp,
      //                                               fontWeight: FontWeight.bold
      //                                             ),
      //                                             children: [
      //                                               TextSpan(
      //                                                 text: '${item.totalAmount}',
      //                                                 style: TextStyle(
      //                                                   color: mainTextColor,
      //                                                   fontSize: 16.sp,
      //                                                   fontWeight: FontWeight.bold
      //                                                 )
      //                                               )
      //                                             ]
      //                                           )
      //                                         )
      //                                       ],
      //                                     )
      //                                   ],
      //                                 ),
      //                               ))
      //                             ],
      //                           ),
      //                         );
      //                       }).toList(),
      //                     ),
      //                   ],
      //                 ),
      //               ),
      //               Container(
      //                 padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 10.h),
      //                 child: Row(
      //                   children: [
      //                     Expanded(child: Text(
      //                       '${item.user!.label}${item.user!.nickname} ${item.user!.mobile}',
      //                       overflow: TextOverflow.ellipsis,
      //                       maxLines: 1,
      //                       style: TextStyle(
      //                         color: textBlackColor,
      //                         fontWeight: FontWeight.bold,
      //                         fontSize: 12.sp
      //                       ),
      //                     )),
      //                     Container(
      //                       width: 90.w,
      //                       margin: EdgeInsets.only(left: 6.w),
      //                       child: ButtonUtil(
      //                         text: '查看订单', 
      //                         fontSize: 14.w, 
      //                         borderRadius: 18.w, 
      //                         height: 26.h, 
      //                         onTop: () {
      //                           Get.toNamed(
      //                             '${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAGE}${AppRouters.SECKILL_ORDER_DETAIL_PAGE}',
      //                             arguments: {
      //                               'seckillOrderId': item.id!,
      //                               'isSeckillPage': false
      //                             }
      //                           );
      //                         }
      //                       ),
      //                     )
      //                   ],
      //                 ),
      //               )
      //             ],
      //           ),
      //         ),
      //       ), () {
      //         Get.toNamed(
      //           '${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAGE}${AppRouters.SECKILL_ORDER_DETAIL_PAGE}',
      //           arguments: {
      //             'seckillOrderId': item.id!,
      //             'isSeckillPage': false
      //           }
      //         );
      //       }),
      //     ),
      //   );
      // }).toList()
      slivers: [
        SliverToBoxAdapter(
          child: widget.commonPageController.userData.value.isTeamLeader == 1 && widget.seckillOrderPageController.tabIndex.value == 1 ? Container(
            margin: EdgeInsets.only(top: 6.h),
            padding: EdgeInsets.symmetric(horizontal: 22.w),
            child: ButtonUtil(
              text: '汇总支付列表信息', 
              fontSize: 14.sp, 
              borderRadius: 5.w, 
              height: 45.h, 
              bgColors: [
                orderSummaryBtnBg,
                orderSummaryBtnBg
              ],
              onTop: () {
                Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAGE}${AppRouters.SECKILL_ORDER_SUMMARY_PAGE}');
              }
            ),
          ) : Container(),
        ),
        SliverList(
          delegate: SliverChildBuilderDelegate((context, index) {
            SeckillOrderItem item = widget.seckillOrderListVo.data![index];
            return Container(
              padding: EdgeInsets.symmetric(horizontal: 16.w),
              margin: EdgeInsets.only(top: 6.h),
              child: InkWellUtil.shakeProofInkWell(Container(
                decoration: BoxDecoration(
                  color: bgWhiteColor,
                  borderRadius: BorderRadius.circular(5.w)
                ),
                child: Container(
                  padding: EdgeInsets.symmetric(horizontal: 8.w),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 10.h),
                        decoration: BoxDecoration(
                          border: Border(
                            bottom: BorderSide(
                              width: .5,
                              color: lineColor
                            )
                          )
                        ),
                        child: Row(
                          children: [
                            Expanded(child: Row(
                              children: [
                                Text(
                                  widget.commonPageController.userData.value.isAdmin == 1 ? '${item.teamName}' : '订单号：${item.orderSn}',
                                  overflow: TextOverflow.ellipsis,
                                  maxLines: 1,
                                  style: TextStyle(
                                    color: textBlackColor,
                                    fontWeight: FontWeight.bold,
                                    fontSize: 12.sp
                                  ),
                                ),
                                widget.commonPageController.userData.value.isTeamLeader == 1 && item.recycleStatus == 1 ? Container(
                                  padding: EdgeInsets.symmetric(horizontal: 4.w),
                                  margin: EdgeInsets.only(left: 4.w),
                                  decoration: BoxDecoration(
                                    color: Color.fromRGBO(230, 0, 18, 0.13),
                                    borderRadius: BorderRadius.circular(2.w)
                                  ),
                                  child: Text(
                                    '回收',
                                    overflow: TextOverflow.ellipsis,
                                    maxLines: 1,
                                    style: TextStyle(
                                      color: mainTextColor,
                                      fontWeight: FontWeight.bold,
                                      fontSize: 10.sp
                                    ),
                                  ),
                                ) : Container()
                              ],
                            )),
                            Text(
                              '${item.statusStr}',
                              style: TextStyle(
                                color: mainTextColor,
                                fontSize: 12.sp
                              ),
                            )
                          ],
                        ),
                      ),
                      Container(
                        padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 10.h),
                        decoration: BoxDecoration(
                          border: Border(
                            bottom: BorderSide(
                              width: .5,
                              color: lineColor
                            )
                          )
                        ),
                        child: Column(
                          children: [
                            Column(
                              children: item.products!.map((productItem) {
                                return Container(
                                  // margin: EdgeInsets.only(bottom: 10.w),
                                  child: Row(
                                    children: [
                                      NetworkImageUtil(
                                        url: productItem.image ?? '', 
                                        width: 64.w, 
                                        height: 64.w,
                                        borderRadius: 5.w,
                                      ),
                                      SizedBox(width: 11.w),
                                      Expanded(child: Container(
                                        constraints: BoxConstraints(
                                          minHeight: 64.w
                                        ),
                                        child: Column(
                                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                          crossAxisAlignment: CrossAxisAlignment.start,
                                          children: [
                                            Text(
                                              '${productItem.title}',
                                              overflow: TextOverflow.ellipsis,
                                              maxLines: 2,
                                              style: TextStyle(
                                                fontSize: 14.sp,
                                                color: textBlackColor
                                              ),
                                            ),
                                            Row(
                                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                              children: [
                                                Text(
                                                  '${item.createdAt}',
                                                  style: TextStyle(
                                                    color: textSubtitleColor,
                                                    fontSize: 12.sp
                                                  ),
                                                ),
                                                Text.rich(
                                                  TextSpan(
                                                    text: '¥',
                                                    style: TextStyle(
                                                      color: mainTextColor,
                                                      fontSize: 12.sp,
                                                      fontWeight: FontWeight.bold
                                                    ),
                                                    children: [
                                                      TextSpan(
                                                        text: '${item.totalAmount}',
                                                        style: TextStyle(
                                                          color: mainTextColor,
                                                          fontSize: 16.sp,
                                                          fontWeight: FontWeight.bold
                                                        )
                                                      )
                                                    ]
                                                  )
                                                )
                                              ],
                                            )
                                          ],
                                        ),
                                      ))
                                    ],
                                  ),
                                );
                              }).toList(),
                            ),
                          ],
                        ),
                      ),
                      Container(
                        padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 10.h),
                        child: Row(
                          children: [
                            Expanded(child: Text(
                              '${item.user!.label}${item.user!.nickname} ${item.user!.mobile}',
                              overflow: TextOverflow.ellipsis,
                              maxLines: 1,
                              style: TextStyle(
                                color: textBlackColor,
                                fontWeight: FontWeight.bold,
                                fontSize: 12.sp
                              ),
                            )),
                            Container(
                              width: 90.w,
                              margin: EdgeInsets.only(left: 6.w),
                              child: ButtonUtil(
                                text: '查看订单', 
                                fontSize: 14.w, 
                                borderRadius: 18.w, 
                                height: 26.h, 
                                onTop: () {
                                  Get.toNamed(
                                    '${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAGE}${AppRouters.SECKILL_ORDER_DETAIL_PAGE}',
                                    arguments: {
                                      'seckillOrderId': item.id!,
                                      'isSeckillPage': false
                                    }
                                  );
                                }
                              ),
                            )
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              ), () {
                Get.toNamed(
                  '${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAGE}${AppRouters.SECKILL_ORDER_DETAIL_PAGE}',
                  arguments: {
                    'seckillOrderId': item.id!,
                    'isSeckillPage': false
                  }
                );
              }),
            );
          }, childCount: widget.seckillOrderListVo.data!.length),
        )
      ]
    );
  }

  @override
  bool get wantKeepAlive => true;
}